package com.jm.common.bean.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

/**
 * @author kong
 */
@Schema(defaultValue = "分页结果")
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class PageVO<T> {
    private Long current = 0L;
    private Long size = 0L;
    private List<T> data = new ArrayList<>();
    private Long total = 0L;
    private Long pages = 0L;
    /**
     * 当数据可以刷新时返回true
     */
    private Boolean refreshed = Boolean.TRUE;

    public PageVO(Long current, Long size, List<T> data, Long total, Long pages) {
        this.current = current;
        this.size = size;
        this.data = data;
        this.total = total;
        this.pages = pages;
    }

    public static <T> PageVO<T> convert(IPage<T> page) {
        return new PageVO<>(page.getCurrent(), page.getSize(), page.getRecords(), page.getTotal(), page.getPages());
    }
}
